package puziran.sofa.memcache.session;

import java.util.Map;

public class MemSession {
	private String sid = "";

	private Map map = null;

	private MemSession(String sid, boolean create) {
		this.sid = sid;
		this.map = MemService.getSession(sid, create);
	}

	public static MemSession getSession(String sid) {
		MemSession session = null;
		session = new MemSession(sid, true);
		return session;
	}

	public static MemSession getSession(String sid, boolean create) {
		MemSession session = null;
		session = new MemSession(sid, create);
		return session;
	}

	public static boolean sessionExists(String sid) {
		return MemService.sessionExists(sid);
	}

	public Object getAttribute(String arg0) {
		return this.map.get(arg0);
	}

	public void invalidate() {
		this.map.clear();
		MemService.removeSession(this.sid);
	}

	public void removeAttribute(String arg0) {
		if ((arg0 == null) || (arg0.trim().length() <= 0)) {
			return;
		}
		this.map.remove(arg0);
		MemService.setSession(this.sid, this.map);
	}

	public void setAttribute(String arg0, Object arg1) {
		if ((arg0 == null) || (arg0.trim().length() <= 0) || (arg1 == null)) {
			return;
		}
		this.map.put(arg0, arg1);
		MemService.setSession(this.sid, this.map);
	}

	public void updateExpiryDate(String sid) {
		MemService.updateExpiryDate(sid);
	}
}